<?php

namespace App\Models\Scm;

use Dcat\Admin\Traits\HasDateTimeFormatter;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Collection;

class Building extends Model
{
    use HasFactory, SoftDeletes, HasDateTimeFormatter;

    /**
     * table name
     * @var string
     */
    protected $table = 'scm_buildings';

    /**
     * json <=> array
     * @var string[]
     */
    protected $casts = [
        'config_data' => 'array',
        'extra_data' => 'array',
    ];

    const  BUILDING_TYPE_OTHER = 0;
    const  BUILDING_TYPE_BLOCK = 1;
    const  BUILDING_TYPE_BUILDING = 2;
    const  BUILDING_TYPE_UNIT = 3;
    const  BUILDING_TYPE_FLOOR = 4;
    const  BUILDING_TYPE_HOUSE = 5;
    const  BUILDING_TYPE_BUSINESS_NETWORK = 6;
    const  BUILDING_TYPE_BARN = 7;
    const  BUILDING_TYPE_PARKING_LOT = 8;
    const  BUILDING_TYPE_PARKING_SPACE = 9;
    const  BUILDING_TYPE_PARKING_GARAGE = 10;
    const  BUILDING_TYPE_PROPERTY_SERVICE_CENTER = 11;

    public static function staticEnums(): array|Collection|null
    {
        return [
            'building_type' => [
                [
                    'id' => self::BUILDING_TYPE_BLOCK,
                    'text' => '苑',
                    'label' => '',
                    'sort' => 1,
                    'default' => false,
                ],
                [
                    'id' => self::BUILDING_TYPE_BUILDING,
                    'text' => '幢',
                    'label' => '',
                    'sort' => 1,
                    'default' => false,
                ],
                [
                    'id' => self::BUILDING_TYPE_UNIT,
                    'text' => '单元',
                    'label' => '',
                    'sort' => 1,
                    'default' => false,
                ],
                [
                    'id' => self::BUILDING_TYPE_FLOOR,
                    'text' => '层',
                    'label' => '',
                    'sort' => 1,
                    'default' => false,
                ],
                [
                    'id' => self::BUILDING_TYPE_HOUSE,
                    'text' => '室',
                    'label' => '',
                    'sort' => 1,
                    'default' => false,
                ],
                [
                    'id' => self::BUILDING_TYPE_BUSINESS_NETWORK,
                    'text' => '商网',
                    'label' => '',
                    'sort' => 1,
                    'default' => false,
                ],
                [
                    'id' => self::BUILDING_TYPE_BARN,
                    'text' => '仓房',
                    'label' => '',
                    'sort' => 1,
                    'default' => false,
                ],
                [
                    'id' => self::BUILDING_TYPE_PARKING_LOT,
                    'text' => '停车场',
                    'label' => '',
                    'sort' => 1,
                    'default' => false,
                ],
                [
                    'id' => self::BUILDING_TYPE_PARKING_SPACE,
                    'text' => '停车位',
                    'label' => '',
                    'sort' => 1,
                    'default' => false,
                ],
                [
                    'id' => self::BUILDING_TYPE_PARKING_GARAGE,
                    'text' => '停车库',
                    'label' => '',
                    'sort' => 1,
                    'default' => false,
                ],
                [
                    'id' => self::BUILDING_TYPE_PROPERTY_SERVICE_CENTER,
                    'text' => '物业服务中心',
                    'label' => '',
                    'sort' => 1,
                    'default' => false,
                ],
                [
                    'id' => self::BUILDING_TYPE_OTHER,
                    'text' => '其它',
                    'label' => '',
                    'sort' => 1,
                    'default' => false,
                ],
            ],
        ];
    }

    public function org(): BelongsTo
    {
        return $this->belongsTo(Org::class, 'org_id', 'id');
    }
}
